-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[base-ui] Create useNumberInput and NumberInput #36119
Conversation
Netlify deploy preview@material-ui/unstyled: parsed: +4.79% , gzip: +4.71% Bundle size reportDetails of bundle changes (Toolpad) |
c4a5b72
to
df004fe
Compare
packages/mui-base/src/NumberInputUnstyled/useNumberInput.test.tsx
Outdated
Show resolved
Hide resolved
@mui/core After using my own implementation, I'm starting to think it's not the best 🥲. I wrote up alternatives in the PR description above, would appreciate your thoughts the options I've came up with or other suggestions! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of the open question regarding the onChange
fire, I would recommend keeping it similar with how the native input number is working. People can still use onBlur
if they want behavior similar to the other option.
packages/mui-base/src/NumberInputUnstyled/NumberInputUnstyled.types.ts
Outdated
Show resolved
Hide resolved
packages/mui-base/src/NumberInputUnstyled/NumberInputUnstyled.types.ts
Outdated
Show resolved
Hide resolved
b6faf9a
to
90777ca
Compare
@michaldudak @mnajdova I've addressed the remaining comments! In particular:
|
The component import is still incorrect: import Unstable_NumberInput as NumberInput from '@mui/base/Unstable_NumberInput'; should be import NumberInput from '@mui/base/Unstable_NumberInput'; |
👌 Fixed in 652c650 @michaldudak |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one nit left, besides that, it's good to go!
There's one more issue we can tackle in a separate PR: slots and classes are not documented in the component API page.
@@ -146,9 +165,9 @@ export default function ComponentsApiContent(props) { | |||
<Heading text="import" hash={`${componentNameKebabCase}-import`} level="h3" /> | |||
<HighlightedCode | |||
code={` | |||
import ${pageContent.name} from '${source}/${pageContent.name}'; | |||
import ${namedImportName} from '${namedImportPath}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be the other way around?
import X from 'X'
is the default import, while import { X } from 'X'
is the named one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let add the component after merging in #37222
import NumberInput, { numberInputClasses } from '@mui/base/Unstable_NumberInput'; | ||
import { styled } from '@mui/system'; | ||
|
||
const CustomNumberInput = React.forwardRef(function CustomNumberInput(props, ref) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's most important to have the Tailwind + Plain CSS demos on the introduction demo. It's the first thing people see when they come to the page :)
} from '@mui/base/Unstable_NumberInput'; | ||
import clsx from 'clsx'; | ||
|
||
const CustomNumberInput = React.forwardRef(function CustomNumberInput( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for introducing new component, it helps with the readibility.
Co-authored-by: zanivan <[email protected]>
Co-authored-by: zanivan <[email protected]>
@mj12albert Thanks for the follow-ups on my comment. Opening individual issues for each point is the way to go 👌 |
This PR will add
useNumberInput
andNumberInput
to base.One step toward closing #19154.
Summary
useNumberInput
implements a number field component that currently supports positive and negative integers, and buttons that can increment and decrement the value. It's mostly adapted fromuseInput
.NumberInput
usesuseNumberInput
internally and is the component counterpart.onChange
of the inner<input>
, aonValueChange
callback is provided that only fires when the value changes to a valid (clamped) value@testing-library/user-event
as some important keyboard interactions like inputting characters one by one and testing each change handler do not work with plainfireEvent
role="spinbutton"
because it doesn't work well with VO (see SpinButton doesn't increment or decrement on Voiceover VO controls microsoft/fluentui#13606)Preview: https://deploy-preview-36119--material-ui.netlify.app/base/react-number-input/